#!/usr/bin/perl
use strict;

system("seq_pairs_substitute_identifiers -m ids.map -i orig.res -v > to.test");
print STDERR "\n";
system("seq_pairs_substitute_identifiers -m ids.map -f ':1' -t ':0' -i to.test -v > back.test");
print STDERR "\n";
system("seq_pairs_remove_duplicate_results -i back.test -v > new.test") and
	print STDERR "seq_pairs_remove_duplicate_results -i back.test -v > new.test\n";

system("seq_pairs_substitute_identifiers -m ids.map -F -i orig.res -v > to2.test");
print STDERR "\n";
system("seq_pairs_substitute_identifiers -m ids.map  -f ':1' -t ':0'  -i to2.test -v > new2.test");
print STDERR "\n";

system("seq_pairs_substitute_identifiers -m ids.map < orig.res -v  > to.test");
print STDERR "\n";
system("seq_pairs_substitute_identifiers -m ids.map  -f ':1' -t ':0'  < to.test -v > back.test");
print STDERR "\n";
system("seq_pairs_remove_duplicate_results -i back.test -v > new3.test");
print STDERR "\n";
system("seq_pairs_substitute_identifiers -m ids.map -F < orig.res -v > to2.test");
print STDERR "\n";
system("seq_pairs_substitute_identifiers -m ids.map  -f ':1' -t ':0'  < to2.test -v > new4.test");
print STDERR "\n";

print STDERR "\tComparing results...\n";
{
	system("tail -n 7 orig.res > compare.test");
	my @files = qw(new.test new2.test new3.test new4.test);
	for my $file(@files)
	{
		my @diff = `diff $file compare.test`;
		if (@diff != 0)
		{
			print STDERR "FAILED: $file orig.res are not the same!\n";
			exit;
		}
	}
}
print STDERR "\tCleaning up...\n";
unlink (glob("*.test"));
print STDERR "\n\tSUCCESS!!!\n\n";


